package dapps.entity.monitor;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springside.modules.utils.DateUtils;

import dapps.entity.IdEntity;
import dapps.entity.user.User;

@Entity
@Table(name = "servicemain")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Servicemain extends IdEntity {

	private static final long serialVersionUID = -172749047563230854L;

	public Servicemain() {
	}	

	@Column(nullable=false,unique=true)
	private String reportyearmonth;	
	private User dutycomp;
	private String inputperson;
	private String inputpersontel;
	private User applicateuser;
	
	@Column(insertable = true, updatable = false)
	private Date insertDate = DateUtils.getCurrentDateTime();

	@Column(insertable = false, updatable = true)
	private Date updateDate;
	
	private Map<Element,Indicator> indicatorMap = new HashMap<Element,Indicator>();
	
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "pk.servicemain")	
	@MapKey(name="pk.element")
    public Map<Element,Indicator> getIndicatorMap() {
            return indicatorMap;
    }
	
	public void setIndicatorMap(Map<Element, Indicator> indicatorMap) {
		this.indicatorMap = indicatorMap;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "user_id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public User getDutycomp() {
		return dutycomp;
	}
	
	

	public void setDutycomp(User dutycomp) {
		this.dutycomp = dutycomp;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "applicateuser_id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public User getApplicateuser() {
		return applicateuser;
	}

	public void setApplicateuser(User applicateuser) {
		this.applicateuser = applicateuser;
	}



	public String getReportyearmonth() {
		return reportyearmonth;
	}

	public void setReportyearmonth(String reportyearmonth) {
		this.reportyearmonth = reportyearmonth;
	}

	public Date getInsertDate() {
		return insertDate;
	}

	public void setInsertDate(Date insertDate) {
		this.insertDate = insertDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}



	public String getInputperson() {
		return inputperson;
	}

	public void setInputperson(String inputperson) {
		this.inputperson = inputperson;
	}

	public String getInputpersontel() {
		return inputpersontel;
	}

	public void setInputpersontel(String inputpersontel) {
		this.inputpersontel = inputpersontel;
	}

	
	@Override
	public String toString() {
		return this.getId().toString();
	}

}
